package algorithm.leetcode.primary.array.removeDuplicates;

import java.util.Arrays;
/**
 * 删除排序数组中的重复项
 * https://blog.csdn.net/dodo5325/article/details/104973675
 */
class RemoveDuplicates {
    public static  int removeDuplicates(int[] nums) {
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        System.out.println(Arrays.toString(nums));
        return i + 1;
    }

    public static void main(String[] args) {
        int[] nums = new int[3];
        nums[0] = 1;
        nums[1] = 1;
        nums[2] = 2;
        System.out.println(removeDuplicates(nums));
    }
}